package org.xinjiang.data.migration.flush.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;

/**
 * @author: 邢卫
 * @date: 2023年12月16日 16:29
 */
@Slf4j
public class DefaultUtils {

    public static String getDefJtzz(String jtzz) {
        if (StringUtils.isEmpty(jtzz)) {
            return "未知";
        }
        return jtzz;
    }

    public static String getName(String name) {
        if (StringUtils.isEmpty(name)) {
            return "";
        }
        return name.trim();
    }

    public static Date getDefCsrq(Date chrq) {
        if (StringUtils.isEmpty(chrq)) {
            try {
                return DateUtils.parseDate("2000-01-01", "yyyy-MM-dd");
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        return chrq;
    }

    public static String getPhone(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return "00000000000";
        }
        return phone;
    }

    public static String getDefSfzh(String sfzh) {
        String def = "000000000000000000";
        if (!StringUtils.isEmpty(sfzh)) {
            def = sfzh;
        }
        return def.trim();
    }

    public static String toDepartName(String departName, String level) {
        if (StringUtils.isEmpty(departName)) {
            return "未知部门名称";
        }
        if (StringUtils.isEmpty(level)) {
            return departName;
        }
        switch (level) {
            case "1"://司法所
                if (!departName.contains("司法所")) {
                    return departName + "司法所";
                }
                return departName;
            case "2"://司法局
            case "3":
                if (!departName.contains("司法局")) {
                    return departName + "司法局";
                }
                return departName;
            case "4"://司法厅
                if (!departName.contains("司法厅")) {
                    return departName + "司法厅";
                }
                return departName;
        }
        return departName;
    }

    public static BigDecimal toGroupType(String level) {
        if (StringUtils.isEmpty(level) || "1".equals(level)) {
            return new BigDecimal(0);
        }
        return new BigDecimal(1);
    }
}
